/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AulaPanel.java
 *
 * Created on 30-nov-2011, 6:56:17
 */
package edu.uoc.tdp.pac4.only5.gui.client.panels.manteniment;

import edu.uoc.tdp.pac4.only5.gui.client.panels.AbstractPanel;
import edu.uoc.tdp.pac4.only5.manager.SpaceManager;
import edu.uoc.tdp.pac4.only5.domain.Space;

import java.rmi.RemoteException;
import java.util.logging.Level;
import java.util.logging.Logger;

import java.util.Date;
import javax.swing.*;

/**
 *
 * @author Alex
 */
public class AulaPanel extends AbstractPanel {

    private SpaceManager spaceManager;
    
    Space space = null;


    /** Creates new form AulaPanel */
    public AulaPanel(SpaceManager spaceManager) {
        super();
        initComponents();
        posicioInicialBotons();
        setLabels();
        this.spaceManager = spaceManager;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lbl_aules_titol = new javax.swing.JLabel();
        lbl_Aula_CodiAula = new javax.swing.JLabel();
        lbl_Aula_Capacitat = new javax.swing.JLabel();
        lbl_Aula_Descripcio = new javax.swing.JLabel();
        lbl_Aula_PreuHora = new javax.swing.JLabel();
        lbl_Aula_PreuDia = new javax.swing.JLabel();
        lbl_Aula_Ciutat = new javax.swing.JLabel();
        lbl_Aula_CodPos = new javax.swing.JLabel();
        lbl_Aula_Adreca = new javax.swing.JLabel();
        lbl_Aula_ComArribar = new javax.swing.JLabel();
        txt_Aula_CodiAula = new javax.swing.JTextField();
        txt_Aula_Descripcio = new javax.swing.JTextField();
        txt_Aula_Capacitat = new javax.swing.JTextField();
        txt_Aula_PreuHora = new javax.swing.JTextField();
        txt_Aula_PreuDia = new javax.swing.JTextField();
        txt_Aula_Ciutat = new javax.swing.JTextField();
        txt_Aula_CodPos = new javax.swing.JTextField();
        txt_Aula_Adreca = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        txt_Aula_ComArribar = new javax.swing.JTextArea();
        btn_Aula_Cancelar = new javax.swing.JButton();
        btn_Aula_Alta = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        btn_Aula_Modificar = new javax.swing.JButton();
        btn_Aula_Eliminar = new javax.swing.JButton();
        btn_Aula_Validar = new javax.swing.JButton();

        lbl_aules_titol.setFont(new java.awt.Font("Verdana", 0, 18));
        lbl_aules_titol.setText("Manteniment aules");
        lbl_aules_titol.setToolTipText("");

        lbl_Aula_CodiAula.setText("Codi aula");

        lbl_Aula_Capacitat.setText("Capacitat");

        lbl_Aula_Descripcio.setText("Descripció");

        lbl_Aula_PreuHora.setText("Preu hora");

        lbl_Aula_PreuDia.setText("Preu dia");

        lbl_Aula_Ciutat.setText("Ciutat");

        lbl_Aula_CodPos.setText("Codi postal");

        lbl_Aula_Adreca.setText("Adreça");

        lbl_Aula_ComArribar.setText("Com arribar hi");

        txt_Aula_Ciutat.setBackground(new java.awt.Color(204, 204, 204));

        txt_Aula_ComArribar.setBackground(new java.awt.Color(204, 204, 204));
        txt_Aula_ComArribar.setColumns(20);
        txt_Aula_ComArribar.setRows(4);
        txt_Aula_ComArribar.setToolTipText("");
        txt_Aula_ComArribar.setDoubleBuffered(true);
        jScrollPane1.setViewportView(txt_Aula_ComArribar);

        btn_Aula_Cancelar.setText("Cancelar");
        btn_Aula_Cancelar.setToolTipText("");
        btn_Aula_Cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_Aula_Cancelar_ActionPerformed(evt);
            }
        });

        btn_Aula_Alta.setText("Alta");
        btn_Aula_Alta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_Aula_Alta_ActionPerformed(evt);
            }
        });

        btn_Aula_Modificar.setText("Modificar");
        btn_Aula_Modificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_Aula_Modificar_ActionPerformed(evt);
            }
        });

        btn_Aula_Eliminar.setText("El·liminar");
        btn_Aula_Eliminar.setToolTipText("");
        btn_Aula_Eliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_Aula_Eliminar_ActionPerformed(evt);
            }
        });

        btn_Aula_Validar.setText("Validar");
        btn_Aula_Validar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_Aula_Validar_ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbl_aules_titol)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(btn_Aula_Alta)
                                .addGap(100, 100, 100)
                                .addComponent(btn_Aula_Modificar)
                                .addGap(127, 127, 127)
                                .addComponent(btn_Aula_Eliminar)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 167, Short.MAX_VALUE)
                                .addComponent(btn_Aula_Cancelar)
                                .addGap(28, 28, 28))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(lbl_Aula_CodiAula)
                                        .addGap(47, 47, 47)
                                        .addComponent(txt_Aula_CodiAula, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(31, 31, 31)
                                        .addComponent(btn_Aula_Validar))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                                .addComponent(lbl_Aula_Descripcio)
                                                .addGap(43, 43, 43)
                                                .addComponent(txt_Aula_Descripcio, javax.swing.GroupLayout.DEFAULT_SIZE, 394, Short.MAX_VALUE))
                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                                .addComponent(lbl_Aula_Capacitat)
                                                .addGap(45, 45, 45)
                                                .addComponent(txt_Aula_Capacitat, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE))
                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                                .addComponent(lbl_Aula_Adreca)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 461, Short.MAX_VALUE))
                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(lbl_Aula_PreuHora)
                                                    .addComponent(lbl_Aula_Ciutat)
                                                    .addComponent(lbl_Aula_ComArribar))
                                                .addGap(24, 24, 24)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 390, Short.MAX_VALUE)
                                                    .addComponent(txt_Aula_Adreca, javax.swing.GroupLayout.DEFAULT_SIZE, 390, Short.MAX_VALUE)
                                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                            .addComponent(txt_Aula_Ciutat, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
                                                            .addComponent(txt_Aula_PreuHora, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE))
                                                        .addGap(18, 18, 18)
                                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                            .addGroup(layout.createSequentialGroup()
                                                                .addComponent(lbl_Aula_CodPos)
                                                                .addGap(18, 18, 18)
                                                                .addComponent(txt_Aula_CodPos, javax.swing.GroupLayout.DEFAULT_SIZE, 123, Short.MAX_VALUE))
                                                            .addGroup(layout.createSequentialGroup()
                                                                .addComponent(lbl_Aula_PreuDia)
                                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 62, Short.MAX_VALUE)
                                                                .addComponent(txt_Aula_PreuDia, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)))))))
                                        .addGap(81, 81, 81)))
                                .addGap(226, 226, 226)))
                        .addGap(24, 24, 24))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 815, Short.MAX_VALUE)
                        .addGap(20, 20, 20))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lbl_aules_titol)
                        .addGap(22, 22, 22)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, false)
                            .addComponent(lbl_Aula_CodiAula)
                            .addComponent(txt_Aula_CodiAula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btn_Aula_Validar))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbl_Aula_Capacitat)
                            .addComponent(txt_Aula_Capacitat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lbl_Aula_Descripcio)
                            .addComponent(txt_Aula_Descripcio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(241, 241, 241)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btn_Aula_Alta)
                            .addComponent(btn_Aula_Modificar)
                            .addComponent(btn_Aula_Cancelar)
                            .addComponent(btn_Aula_Eliminar))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lbl_Aula_PreuHora)
                            .addComponent(txt_Aula_PreuHora, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lbl_Aula_PreuDia)
                            .addComponent(txt_Aula_PreuDia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lbl_Aula_Ciutat)
                            .addComponent(lbl_Aula_CodPos)
                            .addComponent(txt_Aula_Ciutat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txt_Aula_CodPos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lbl_Aula_Adreca)
                            .addComponent(txt_Aula_Adreca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(20, 20, 20)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbl_Aula_ComArribar)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(56, 56, 56))))
        );
    }// </editor-fold>//GEN-END:initComponents

private void btn_Aula_Alta_ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_Aula_Alta_ActionPerformed
// TODO add your handling code here:
    try {
        // Amb els camps carregats al panel, es fa l'alta de l'aula
        space = new Space();

        if (carregaSpace(space)) {
                spaceManager.addSpace(space);
                netejaCampsPanel();
                txt_Aula_CodiAula.setText("");
                posicioInicialBotons();
        }
    } catch (RemoteException ex) {
        Logger.getLogger(AulaPanel.class.getName()).log(Level.SEVERE, null, ex);
    } catch(NullPointerException e) {
            Logger.getLogger(AulaPanel.class.getName()).log(Level.SEVERE, null, e);
    }
}//GEN-LAST:event_btn_Aula_Alta_ActionPerformed

private void btn_Aula_Modificar_ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_Aula_Modificar_ActionPerformed
// TODO add your handling code here:
    space = null;
    int optionType = JOptionPane.YES_NO_OPTION;
    int messageType = JOptionPane.INFORMATION_MESSAGE;

    try {
        // Amb el codi d'usuari, modifica el registre de la taula users
        space = new Space();

        if (carregaSpace(space)) {
            // Confirmació de la modificacio
            Integer sel = JOptionPane.showConfirmDialog(this,"Segur que vols fer la modificació en aquesta aula?","Manteniment aules - Confirmació", optionType, messageType);
            if (sel != 1) {
                spaceManager.modifySpace(space);
            }
            netejaCampsPanel();
            txt_Aula_CodiAula.setText("");
            posicioInicialBotons();
        }

    } catch (RemoteException ex) {
        Logger.getLogger(AulaPanel.class.getName()).log(Level.SEVERE, null, ex);
    } catch(NullPointerException e) {}
}//GEN-LAST:event_btn_Aula_Modificar_ActionPerformed

private void btn_Aula_Eliminar_ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_Aula_Eliminar_ActionPerformed
// TODO add your handling code here:
    int optionType = JOptionPane.YES_NO_OPTION;
    int messageType = JOptionPane.INFORMATION_MESSAGE;

    try {
        // Confirmació d'esborrat
        Integer sel = JOptionPane.showConfirmDialog(this,"Segur que vols eliminar aquesta aula?","Manteniment aules - Confirmació", optionType, messageType);
        // Esborrat usuari
        String codiAula = txt_Aula_CodiAula.getText();
        if (sel != 1) {
            spaceManager.deleteSpace(codiAula);
        }
        netejaCampsPanel();
        txt_Aula_CodiAula.setText("");
        posicioInicialBotons();

    } catch (RemoteException ex) {
        Logger.getLogger(AulaPanel.class.getName()).log(Level.SEVERE, null, ex);
    } catch(NullPointerException e) {}
}//GEN-LAST:event_btn_Aula_Eliminar_ActionPerformed

private void btn_Aula_Cancelar_ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_Aula_Cancelar_ActionPerformed
// TODO add your handling code here:
    netejaCampsPanel();
    txt_Aula_CodiAula.setText("");
    posicioInicialBotons();

}//GEN-LAST:event_btn_Aula_Cancelar_ActionPerformed

private void btn_Aula_Validar_ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_Aula_Validar_ActionPerformed
// TODO add your handling code here:
    space = null;
    try {
    if (comprovaCampValidInt(txt_Aula_CodiAula.getText(), lbl_Aula_CodiAula.getText())) {
        space = spaceManager.getSpace(txt_Aula_CodiAula.getText());
        // Assigna els camps de l'aula trobada a les caixes
        activaBotonsNoAlta();
        carregaCampsPanel(space);
        }
    
    } catch (RemoteException ex) {
    } catch(NullPointerException e){
        // Prepara camps per fer l'alta d'usuari.
        activaBotonsAlta();
        netejaCampsPanel();
    }

}//GEN-LAST:event_btn_Aula_Validar_ActionPerformed

    /**
     * Carrega el registre sobre els camps del panel per a ser mostrats. 
     * @autor Alex
     * @param aula
     * @return void
     */
    public void carregaCampsPanel(Space space) {
        txt_Aula_Capacitat.setText(String.valueOf(space.getCapacity()));
        txt_Aula_Descripcio.setText(space.getDescription());
        txt_Aula_PreuHora.setText(String.valueOf(space.getPriceHour()));
        txt_Aula_PreuDia.setText(String.valueOf(space.getPriceDay()));
        txt_Aula_Ciutat.setText(space.getCity());
        txt_Aula_CodPos.setText(String.valueOf(space.getPostalCode()));
        txt_Aula_Adreca.setText(space.getAddresss());
        txt_Aula_ComArribar.setText(space.getHowToGet());
    }

   /**
     * Netaja els camps del panel. 
     * @autor Alex
     * @param 
     * @return void
     */
public void netejaCampsPanel() {
        txt_Aula_CodiAula.setEnabled(true);
        txt_Aula_Capacitat.setText("0");
        txt_Aula_Descripcio.setText("");
        txt_Aula_PreuHora.setText("0");
        txt_Aula_PreuDia.setText("0");
        txt_Aula_Ciutat.setText("");
        txt_Aula_CodPos.setText("");
        txt_Aula_Adreca.setText("");
        txt_Aula_ComArribar.setText("");
    }

/**
     * Activa el botons amb les accions a fer en la posició inicial.
     * @autor Alex
     * @return void
     */
    public void posicioInicialBotons(){
        btn_Aula_Alta.setEnabled(false);
        btn_Aula_Modificar.setEnabled(false);
        btn_Aula_Eliminar.setEnabled(false);
        btn_Aula_Cancelar.setEnabled(false);
    }
/**
     * Activa el botons amb les accions a fer en la posició "Alta aula".  
     * @autor Alex
     * @return void
     */
    public void activaBotonsAlta(){
        btn_Aula_Alta.setEnabled(true);
        btn_Aula_Modificar.setEnabled(false);
        btn_Aula_Eliminar.setEnabled(false);
        btn_Aula_Cancelar.setEnabled(true);

        txt_Aula_CodiAula.setEnabled(true);
 }
/**
     * Activa el botons amb les accions a fer en la posició 
     * "Modificar aula" i "Eliminar aula".  
     * @autor Alex
     * @return void
     */
    public void activaBotonsNoAlta(){
        btn_Aula_Alta.setEnabled(false);
        btn_Aula_Modificar.setEnabled(true);
        btn_Aula_Eliminar.setEnabled(true);
        btn_Aula_Cancelar.setEnabled(true);
        txt_Aula_CodiAula.setEnabled(false);
}
    /**
     * Comprova que el camp no sigui NULL
     * @autor Alex
     * @param camp a validar, nom camp a validar
     * @return true/false
     */
    public boolean comprovaCampValid(String camp, String titol) {
    int optionType = JOptionPane.DEFAULT_OPTION;
    int messageType = JOptionPane.ERROR_MESSAGE;

        if ( camp != null && !camp.equals("") ) {
            return true;
        } else {
            JOptionPane.showConfirmDialog(this,"Camp "+titol+" obligatori !","Manteniment aules - Validació", optionType, messageType);
            return false;
        }
    }

    /**
     * Comprova que el camp sigui nummèric i que no sigui NULL
     * @autor Alex
     * @param camp a validar, nom camp a validar
     * @return true/false
     */
    public boolean comprovaCampValidInt(String camp, String titol) {
    int optionType = JOptionPane.DEFAULT_OPTION;
    int messageType = JOptionPane.ERROR_MESSAGE;

    // Comprova que sigui numèric
    try {
        Integer.parseInt(camp);
        return true;
    } catch (Exception e) {
        JOptionPane.showConfirmDialog(this,"Camp "+titol+" és obligatori i ha de ser numèric !","Manteniment aules - Validació", optionType, messageType);
        return false;
    }
    
}
    /**
     * Comprova que el camp sigui nummèric i que no sigui NULL
     * @autor Alex
     * @param camp a validar, nom camp a validar
     * @return true/false
     */
    public boolean comprovaCampValidDouble(String camp, String titol) {
    int optionType = JOptionPane.DEFAULT_OPTION;
    int messageType = JOptionPane.ERROR_MESSAGE;

    // Comprova que sigui numèric
    try {
        Double.parseDouble(camp);
        return true;
    } catch (Exception e) {
        JOptionPane.showConfirmDialog(this,"Camp "+titol+" és obligatori i ha de ser numèric !","Manteniment aules - Validació", optionType, messageType);
        return false;
    }
    
}

    /**
     * Mètode que carrega els camps del registre i fa les validacions bàsiques.
     * @autor Alex
     * @param space
     * @return true/false
     */
    public boolean carregaSpace(Space space) {
    boolean totOK = true;
    String varStr1 = "";
    String varStr2 = "";
    Date avui = new Date();

    /*
     * Codi aula
     */    
    varStr1 = txt_Aula_CodiAula.getText();
    varStr2 = lbl_Aula_CodiAula.getText();
    if (comprovaCampValidInt(varStr1, varStr2)) space.setSpaceId(Integer.parseInt(varStr1));
    else totOK = false;

    /*
     * Descripció
     */    
    varStr1 = txt_Aula_Descripcio.getText();
    varStr2 = lbl_Aula_Descripcio.getText();
    if (comprovaCampValid(varStr1, varStr2)) space.setDescription(varStr1);
    else totOK = false;

    /*
     * Capacitat
     */    
    varStr1 = txt_Aula_Capacitat.getText();
    varStr2 = lbl_Aula_Capacitat.getText();
    if (comprovaCampValidInt(varStr1, varStr2)) space.setCapacity(Integer.parseInt(varStr1));
    else totOK = false;

    /*
     * Preu hora
     */    
    varStr1 = txt_Aula_PreuHora.getText();
    varStr2 = lbl_Aula_PreuHora.getText();
    if (comprovaCampValidDouble(varStr1, varStr2)) space.setPriceHour(Double.parseDouble(varStr1));
    else totOK = false;

    /*
     * Preu dia
     */    
    varStr1 = txt_Aula_PreuDia.getText();
    varStr2 = lbl_Aula_PreuDia.getText();
    if (comprovaCampValidDouble(varStr1, varStr2)) space.setPriceDay(Double.parseDouble(varStr1));
    else totOK = false;

    
    /*
     * Com arribar-hi
     */    
    space.setHowToGet(txt_Aula_ComArribar.getText());
    
    /*
     * Codi postal
     */    
    varStr1 = txt_Aula_CodPos.getText();
    varStr2 = lbl_Aula_CodPos.getText();
    if (comprovaCampValidInt(varStr1, varStr2)) space.setPostalCode(Integer.parseInt(varStr1));
    else totOK = false;
    
    /*
     * Ciutat
     */    
    varStr1 = txt_Aula_Ciutat.getText();
    space.setHowToGet(varStr1);
    
    /*
     * Adreça
     */    
    varStr1 = txt_Aula_Adreca.getText();
    varStr2 = lbl_Aula_Adreca.getText();
    if (comprovaCampValid(varStr1, varStr2)) space.setAddresss(varStr1);
    else totOK = false;

    /*
     * Data creació
     */    
    space.setCreationDate(avui);

    /*
     * Usuari creador
     */    
    space.setCreationUser("");

    /*
     * Data aula inactiva
     */    
    space.setInactivationDate(avui);
    
    /*
     * Usuari aula inactiva
     */    
    space.setInactivationUser("");

    /*
     * Data registre
     */    
    space.setRecordDate(avui);
    
    return totOK;
}




    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_Aula_Alta;
    private javax.swing.JButton btn_Aula_Cancelar;
    private javax.swing.JButton btn_Aula_Eliminar;
    private javax.swing.JButton btn_Aula_Modificar;
    private javax.swing.JButton btn_Aula_Validar;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel lbl_Aula_Adreca;
    private javax.swing.JLabel lbl_Aula_Capacitat;
    private javax.swing.JLabel lbl_Aula_Ciutat;
    private javax.swing.JLabel lbl_Aula_CodPos;
    private javax.swing.JLabel lbl_Aula_CodiAula;
    private javax.swing.JLabel lbl_Aula_ComArribar;
    private javax.swing.JLabel lbl_Aula_Descripcio;
    private javax.swing.JLabel lbl_Aula_PreuDia;
    private javax.swing.JLabel lbl_Aula_PreuHora;
    private javax.swing.JLabel lbl_aules_titol;
    private javax.swing.JTextField txt_Aula_Adreca;
    private javax.swing.JTextField txt_Aula_Capacitat;
    private javax.swing.JTextField txt_Aula_Ciutat;
    private javax.swing.JTextField txt_Aula_CodPos;
    private javax.swing.JTextField txt_Aula_CodiAula;
    private javax.swing.JTextArea txt_Aula_ComArribar;
    private javax.swing.JTextField txt_Aula_Descripcio;
    private javax.swing.JTextField txt_Aula_PreuDia;
    private javax.swing.JTextField txt_Aula_PreuHora;
    // End of variables declaration//GEN-END:variables

    @Override
    protected void setLabels() {

        // Etiquetes
        lbl_aules_titol.setText(getText("lbl_aules_titol")); 
        lbl_Aula_CodiAula.setText(getText("lbl_Aula_CodiAula")); 
        lbl_Aula_Capacitat.setText(getText("lbl_Aula_Capacitat")); 
        lbl_Aula_PreuHora.setText(getText("lbl_Aula_PreuHora")); 
        lbl_Aula_PreuDia.setText(getText("lbl_Aula_PreuDia")); 
        lbl_Aula_Ciutat.setText(getText("lbl_Aula_Ciutat")); 
        lbl_Aula_CodPos.setText(getText("lbl_Aula_CodPos")); 
        lbl_Aula_Adreca.setText(getText("lbl_Aula_Adreca")); 
        lbl_Aula_ComArribar.setText(getText("lbl_Aula_ComArribar")); 

        //Botons
        btn_Aula_Alta.setText(getText("btn_Aula_Alta")); 
        btn_Aula_Cancelar.setText(getText("btn_Aula_Cancelar")); 
        btn_Aula_Eliminar.setText(getText("btn_Aula_Eliminar")); 
        btn_Aula_Modificar.setText(getText("btn_Aula_Modificar")); 
        btn_Aula_Validar.setText(getText("btn_Aula_Validar")); 
    }
}
